package com.lawalong.redbubblemicroservice.controller;

import com.lawalong.redbubblemicroservice.model.Treasure;
import com.lawalong.redbubblemicroservice.util.TreasureEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/")
public class RedbubbleController {

    @Value("${DOCKER_ENV_VARIABLE:(No environment variable found)}")
    private String docker_env_variable;

    // Say Hello
    @GetMapping("/") //default: localhost:8080/
    public String sayHello() {

        StringBuilder sb = new StringBuilder();
        sb.append("<h1>Hello world</h1>")
                .append("<h2>Hello Redbubble</h2>")
                .append("<br>")
                .append("Docker Environment Variables: ")
                .append("<b><font color='red'>") // text-color,style
                .append(docker_env_variable)
                .append("</font></b>");

        String response = sb.toString();

        System.out.println("Web Request, ==>> say hello" + "Response" + response); //log

        return response;
    }

    // Get Treasure
    @Autowired
    private TreasureEngine treasureEngine;
    @GetMapping(value = "/treasure", produces = {"application/xml;charset=UTF-8"})
    public String getTreauser() {
        String response = treasureEngine.jaxbTreasureObjectToXML();
        System.out.println("Web Request, ==>> get Treasure" + "Response" + response); //log
        return response;
    }

    // Get Health status
    @GetMapping("/_health")
    public String getHealth() {
        String response = "{\"app\":{\"message\":\"Application is running\",\"success\":true}}";
        System.out.println("Web Request, ==>> get health" + "Response" + response); //log
        return response;
    }

}

